#include "Define_Global.h"
#include "ArmPlatformmgrTool.h"

using std::string;
using std::map;

ArmPlatformmgrTool::ArmPlatformmgrTool(void)
{
}

ArmPlatformmgrTool::~ArmPlatformmgrTool(void)
{
}

map<string, Property> ArmPlatformmgrTool::LoadXML()
{
	map<string, Property> item_map;
	string xmlPath = "Update.xml";

	TiXmlDocument *myDocument = new TiXmlDocument(xmlPath.c_str());
	if (myDocument == NULL) {
		return item_map;
	}
	myDocument->LoadFile();
	//获得根元素
	TiXmlElement *RootElement = myDocument->RootElement();	// Update

	//1、
	string itemName = "3288";
	TiXmlElement *CheckResolutionItem = RootElement->FirstChildElement(itemName.c_str());
	InsertToItemMap(item_map, itemName, CheckResolutionItem);

	//2、
	itemName = "3399";
	TiXmlElement *CheckAeroItem = RootElement->FirstChildElement(itemName.c_str());
	InsertToItemMap(item_map, itemName, CheckAeroItem);

	//3、
	itemName = "mt6785";
	TiXmlElement *CheckSysFirewallStateItem = RootElement->FirstChildElement(itemName.c_str());
	InsertToItemMap(item_map, itemName, CheckSysFirewallStateItem);

	myDocument->Clear();
	delete myDocument;
	return item_map;
}

Property ArmPlatformmgrTool::LoadGeneralInfo( string itemName, TiXmlElement *element )
{
	Property item;
	// name 属性
	item.Update = itemName;

	// 平台类型
	TiXmlElement *BoardPlatform = element->FirstChildElement();
    if (!BoardPlatform) {
        std::cout << "BoardPlatform parse failed!\n" << std::endl;;
        return;
    }
	string boardPlatform = BoardPlatform->FirstChild()->Value();

	// 分辨率
	TiXmlElement *DisplaySize = BoardPlatform->NextSiblingElement();
    if (!DisplaySize) {
        std::cout << "DisplaySize parse failed!\n" << std::endl;;
        return;
    }
	string displaySize = DisplaySize->FirstChild()->Value();

	// 类型识别，如 mnt 或者项目编号等
	TiXmlElement *CheckIdentity = DisplaySize ->NextSiblingElement();
    if (!CheckIdentity) {
        std::cout << "DisplaySize parse failed!\n" << std::endl;;
        return;
    }
	string checkIdentity = CheckIdentity->FirstChild()->Value();

	// 升级文件名称
	TiXmlElement *FileName = CheckIdentity->NextSiblingElement();
    if (!FileName) {
        std::cout << "FileName parse failed!\n" << std::endl;;
        return;
    }
	string fileName = FileName->FirstChild()->Value();

	// 目标路径
	TiXmlElement *DestPath = FileName->NextSiblingElement();
    if (!DestPath) {
        std::cout << "DestPath parse failed!\n" << std::endl;;
        return;
    }
	string destPath = DestPath->FirstChild()->Value();

	// 文件重命名
	TiXmlElement *FileRename = DestPath->NextSiblingElement();
    if (!FileRename) {
        std::cout << "FileRename parse failed!\n" << std::endl;;
        return;
    }
	string fileRename = FileRename->FirstChild()->Value();

	// 系统 remount 指令
	TiXmlElement *SystemRemount = FileRename->NextSiblingElement();
    if (!SystemRemount) {
        std::cout << "SystemRemount parse failed!\n" << std::endl;;
        return;
    }
	string systemRemount = SystemRemount->FirstChild()->Value();

	// 用户组
	TiXmlElement *UserGroup = SystemRemount->NextSiblingElement();
    if (!UserGroup) {
        std::cout << "UserGroup parse failed!\n" << std::endl;;
        return;
    }
	string userGroup = UserGroup->FirstChild()->Value();

	// 文件权限
	TiXmlElement *FilePermission = UserGroup->NextSiblingElement();
    if (!FilePermission) {
        std::cout << "FilePermission parse failed!\n" << std::endl;;
        return;
    }
	string filePermission = FilePermission->FirstChild()->Value();

	return item;
}

void ArmPlatformmgrTool::InsertToItemMap(map<string, Property> &item_map,string itemName, TiXmlElement *CheckItemXmlNode )
{
	Property item = LoadGeneralInfo(itemName, CheckItemXmlNode);

}